import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { getAgeByIdCard } from '#/utils/calculate';

import { renderDict } from '#/utils/render';
import { DictEnum } from '@vben/constants';
import { cloneDeep, getPopupContainer } from '@vben/utils';
import dayjs from 'dayjs';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'patientName',
    label: '用户姓名',
  },
  {
    component: 'Input',
    fieldName: 'idCard',
    label: '身份证号',
  },
  {
    component: 'Input',
    fieldName: 'phonenumber',
    label: '手机号码',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '用户姓名',
    field: 'patientName',
  },
  {
    title: '手机号码',
    field: 'phonenumber',
  },
  {
    title: '性别 ',
    field: 'sex',
    slots: {
      default: ({ row }) => {
        return renderDict(row.sex, DictEnum.SYS_USER_SEX);
      },
    },
  },
  {
    title: '身份证号',
    field: 'idCard',
  },
  {
    title: '年龄',
    field: 'age',
    formatter: ({ row }) => {
      return getAgeByIdCard(row.idCard) || '--';
    },
  },
  {
    title: '所属实验',
    field: 'trialName',
  },
  {
    title: '申请日期',
    field: 'applicationDate',
  },
  {
    title: '入组日期',
    field: 'enrollmentDate',
  },
  /**
   * 入组状态
   * '0' - 已申请，待审核
   * '1' - 审核通过，在组中
   * '2' - 已完成
   * '3' - 已退出
   * '4' - 已拒绝
   */
  {
    title: '账户状态',
    field: 'status',
    slots: {
      default: ({ row }) => {
        return renderDict(row.status, 'patient_group_status');
      },
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '患者ID (主键)',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '调整时间',
    fieldName: 'setEnrollTime',
    component: 'InputNumber',
    defaultValue: 0,
    // rules: 'required',
    componentProps: {
      //数值精度
      precision: 0,
      addonAfter: '天',
      //步数
      step: 1,
      style: {
        width: '100%',
      },
    },
  },
  {
    label: '入组日期',
    fieldName: 'enrollmentDate',
    component: 'DatePicker',
    disabled: true,
    rules: 'required',
    componentProps: {
      format: 'YYYY-MM-DD',
      showTime: true,
      valueFormat: 'YYYY-MM-DD',
      getPopupContainer,
    },
  },
];
